package com.jiang.config;

import com.jiang.rediscache.RedisCache;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.cache.support.SimpleCacheManager;
import org.springframework.context.annotation.Bean;
import org.springframework.context.annotation.Configuration;
import org.springframework.data.redis.core.RedisTemplate;

import java.util.ArrayList;
import java.util.List;

@Configuration
public class RedisCacheConfig {
    @Autowired
    private RedisTemplate redisTemplate;

    @Bean
    public SimpleCacheManager simpleCacheManager(){
        SimpleCacheManager cacheManager=new SimpleCacheManager();
        List<RedisCache> caches= new ArrayList<RedisCache>();
        RedisCache redisCache=new RedisCache();
        redisCache.setName("cache0");
        redisCache.setRedisTemplate(redisTemplate);
        caches.add(redisCache);
        cacheManager.setCaches(caches);
        return cacheManager;
    }
}
